package com.Eastiy.EXO.View;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.LinearLayout;
import android.widget.ScrollView;

public class NewViewSV extends ScrollView {
    /* access modifiers changed from: private */
    public View childView;
    private Context context;
    private int downX;
    private int downY;
    /* access modifiers changed from: private */
    public boolean isFinishAnimation = true;
    private int lastX;
    private int lastY;
    /* access modifiers changed from: private */
    public Rect normal = new Rect();

    public NewViewSV(Context context2, AttributeSet attributeSet) {
        super(context2, attributeSet);
    }

    public NewViewSV(Context context2, Object obj, Object obj2, Object obj3, Object obj4, Object obj5) {
        super(context2);
        this.context = context2;
        setVerticalScrollBarEnabled(false);
        if (!(obj == null || obj2 == null)) {
            setLayoutParams(new LinearLayout.LayoutParams(((Integer) obj).intValue(), ((Integer) obj2).intValue()));
        }
        if (obj3 == new Integer(0)) {
            setBackgroundDrawable(new ColorDrawable(Color.parseColor((String) obj4)));
        } else if (obj3 == new Integer(1)) {
            setBackgroundDrawable(ASUI.roundBG(obj4, obj5, (String) null, (Object) null));
        } else {
            if (obj3 == new Integer(2)) {
            }
        }
    }

    private boolean isNeedAnimation() {
        return !this.normal.isEmpty();
    }

    private boolean isNeedMove() {
        int measuredHeight = this.childView.getMeasuredHeight();
        int measuredHeight2 = getMeasuredHeight();
        int scrollY = getScrollY();
        return scrollY <= 0 || scrollY >= measuredHeight - measuredHeight2;
    }

    /* access modifiers changed from: protected */
    @Override
    public void onFinishInflate() {
        super.onFinishInflate();
        if (getChildCount() > 0) {
            this.childView = getChildAt(0);
        }
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent motionEvent) {
        boolean z = false;
        int x = (int) motionEvent.getX();
        int y = (int) motionEvent.getY();
        switch (motionEvent.getAction()) {
            case 0:
                this.downX = x;
                this.lastX = x;
                this.downY = y;
                this.lastY = y;
                break;
            case 2:
                int abs = Math.abs(x - this.downX);
                int abs2 = Math.abs(y - this.downY);
                if (abs2 > abs && abs2 >= ((int) (((double) this.context.getResources().getDisplayMetrics().heightPixels) * 0.15d))) {
                    z = true;
                }
                this.lastX = x;
                this.lastY = y;
                break;
        }
        return z;
    }

    @Override
    public boolean onTouchEvent(MotionEvent motionEvent) {
        if (this.childView == null || !this.isFinishAnimation) {
            return super.onTouchEvent(motionEvent);
        }
        int y = (int) motionEvent.getY();
        switch (motionEvent.getAction()) {
            case 0:
                this.lastY = y;
                break;
            case 1:
                if (isNeedAnimation()) {
                    TranslateAnimation translateAnimation = new TranslateAnimation((float) 0, (float) 0, (float) 0, (float) (-(this.childView.getBottom() - this.normal.bottom)));
                    translateAnimation.setDuration((long) 200);
                    translateAnimation.setAnimationListener(new Animation.AnimationListener(this) {
                        private final NewViewSV this$0;

                        {
                            this.this$0 = r1;
                        }

                        static NewViewSV access$0(AnonymousClass100000000 r1) {
                            return r1.this$0;
                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {
                            this.this$0.isFinishAnimation = true;
                            this.this$0.childView.clearAnimation();
                            this.this$0.childView.layout(this.this$0.normal.left, this.this$0.normal.top, this.this$0.normal.right, this.this$0.normal.bottom);
                            this.this$0.normal.setEmpty();
                        }

                        @Override
                        public void onAnimationRepeat(Animation animation) {
                        }

                        @Override
                        public void onAnimationStart(Animation animation) {
                            this.this$0.isFinishAnimation = false;
                        }
                    });
                    this.childView.startAnimation(translateAnimation);
                    break;
                }
                break;
            case 2:
                int i = y - this.lastY;
                if (isNeedMove()) {
                    if (this.normal.isEmpty()) {
                        this.normal.set(this.childView.getLeft(), this.childView.getTop(), this.childView.getRight(), this.childView.getBottom());
                    }
                    this.childView.layout(this.childView.getLeft(), this.childView.getTop() + (i / 2), this.childView.getRight(), (i / 2) + this.childView.getBottom());
                }
                this.lastY = y;
                break;
        }
        return super.onTouchEvent(motionEvent);
    }
}
